package com.freshfresh.utils;

import android.text.TextPaint;
import android.widget.TextView;
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class StringUtil {
	private static String hexString = "1234567GHJKLMNBV";

	public static int SExchangeI(String paramString) {
		return new BigDecimal(paramString).intValue();
	}

	public static String StringFilter(String paramString)
			throws PatternSyntaxException {
		return Pattern
				.compile(
						"[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；。，、？]")
				.matcher(paramString).replaceAll("").trim();
	}

	public static boolean isBlank(String str) {
		int strLen;
		if ((str == null) || ((strLen = str.length()) == 0)
				|| str.equals("null")) {
			return true;
		}
		for (int i = 0; i < strLen; ++i) {
			if (!(Character.isWhitespace(str.charAt(i)))) {
				return false;
			}
		}
		return true;
	}

	public static String bin2hex(String paramString) {
		char[] arrayOfChar = "0123456789ABCDEF".toCharArray();
		StringBuffer localStringBuffer = new StringBuffer("");
		byte[] arrayOfByte = paramString.getBytes();
		for (int i = 0;; i++) {
			if (i >= arrayOfByte.length)
				return localStringBuffer.toString();
			localStringBuffer
					.append(arrayOfChar[((0xF0 & arrayOfByte[i]) >> 4)]);
			localStringBuffer.append(arrayOfChar[(0xF & arrayOfByte[i])]);
		}
	}

	public static boolean dateCompare(String paramString1, String paramString2) {
		java.sql.Date localDate1 = java.sql.Date.valueOf(paramString1);
		java.sql.Date localDate2 = java.sql.Date.valueOf(paramString2);
		boolean bool = true;
		if (localDate2.compareTo(localDate1) > 0)
			bool = false;
		return bool;
	}

	public static String formatPrice(String paramString) {
		return formatPrice("￥0.00", paramString);
	}

	public static String formatPrice(String paramString1, String paramString2) {
		if (paramString2 == null)
			return "暂无价格";
		return formatStringToWish(paramString1, paramString2);
	}

	public static String formatStringToWish(String paramString1,
			String paramString2) {
		if (paramString1 == null)
			return new DecimalFormat("￥00.00").format(Double
					.parseDouble(paramString2));
		return new DecimalFormat(paramString1).format(Double
				.parseDouble(paramString2));
	}

	public static String getAmt(String paramString) {
		switch (paramString.length()) {
		default:
			return "0000000000";
		case 1:
			return "00000000000" + paramString;
		case 2:
			return "0000000000" + paramString;
		case 3:
			return "000000000" + paramString;
		case 4:
			return "00000000" + paramString;
		case 5:
			return "0000000" + paramString;
		case 6:
			return "000000" + paramString;
		case 7:
			return "00000" + paramString;
		case 8:
			return "0000" + paramString;
		case 9:
			return "000" + paramString;
		case 10:
			return "00" + paramString;
		case 11:
			return "0" + paramString;
		case 12:
		}
		return paramString;
	}

	public static String[] getDistinct(String[] paramArrayOfString) {
		ArrayList localArrayList = new ArrayList();
		for (int i = 0;; i++) {
			if (i >= paramArrayOfString.length)
				return (String[]) localArrayList.toArray(new String[0]);
			if (!localArrayList.contains(paramArrayOfString[i]))
				localArrayList.add(paramArrayOfString[i]);
		}
	}

	public static String hex2bin(String paramString) {
		char[] arrayOfChar = paramString.toCharArray();
		byte[] arrayOfByte = new byte[paramString.length() / 2];
		for (int i = 0;; i++) {
			if (i >= arrayOfByte.length)
				return new String(arrayOfByte);
			arrayOfByte[i] = ((byte) (0xFF & 16
					* "0123456789ABCDEF".indexOf(arrayOfChar[(i * 2)])
					+ "0123456789ABCDEF".indexOf(arrayOfChar[(1 + i * 2)])));
		}
	}

	public static boolean isChinese(String paramString) {
		return Pattern.compile("[一-龥]").matcher(paramString).find();
	}

	public static String isString(String paramString) {
		if ((paramString == null) || (paramString.equals(""))
				|| (paramString.length() == 0) || (paramString.equals("null")))
			paramString = "";
		return paramString;
	}

	public static List<String> removeDuplicateWithOrder(List<String> paramList) {
		HashSet localHashSet = new HashSet();
		ArrayList localArrayList = new ArrayList();
		Iterator localIterator = paramList.iterator();
		while (true) {
			if (!localIterator.hasNext()) {
				paramList.clear();
				paramList.addAll(localArrayList);
				return paramList;
			}
			Object localObject = localIterator.next();
			if (localHashSet.add(localObject))
				localArrayList.add(localObject);
		}
	}

	public static void setFakeBoldText(TextView paramTextView) {
		paramTextView.getPaint().setFakeBoldText(true);
	}

	public static String toStringVersion(String paramString) {
		ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(
				paramString.length() / 2);
		for (int i = 0;; i += 2) {
			if (i >= paramString.length())
				return new String(localByteArrayOutputStream.toByteArray());
			localByteArrayOutputStream.write(hexString.indexOf(paramString
					.charAt(i)) << 4
					| hexString.indexOf(paramString.charAt(i + 1)));
		}
	}
}